{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">题库名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="question_title" lay-verify="required" placeholder="题库名称" class="layui-input ">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">题库分类：</label>
                            <div class="layui-input-block">
                                <select name="question_subject_id" >
                                    {volist name="subject" id="vo"}
                                    <option value="{$vo['subject_id']}">{$vo['subject_name']}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">年级：</label>
                            <div class="layui-input-block">
                                <select name="question_grade_id" >
                                    {volist name="grade" id="vo"}
                                    <option value="{$vo['grade_id']}">{$vo['grade_name']}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">是否免费：</label>
                            <div class="layui-input-block">
                                <select name="question_type" lay-filter="aaaaa">
                                    <option value="1" selected>是</option>
                                    <option value="2" >否</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 bbbbb hidden">
                            <label class="layui-form-label">价格：</label>
                            <div class="layui-input-block">
                                <input type="text" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" name="question_price" placeholder="价格" class="layui-input ">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">是否上架：</label>
                            <div class="layui-input-block">
                                <select name="question_status" >
                                    <option value="1" selected>上架</option>
                                    <option value="2" >下架</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">添加
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.on('submit(component-form-element)', function (data) {
//            data.field.lunbo_content = editor.txt.html();
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('add')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('question/index')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
            form.on('select(aaaaa)', function(data){
                if(data.value==1){
                    $(".bbbbb").addClass('hidden');
                    $('input[name="question_price"]').removeAttr('lay-verify');
                }else{
                    $(".bbbbb").removeClass('hidden');
                    $('input[name="question_price"]').attr('lay-verify', 'required');
                }
            });
    });

</script>

</body>
</html>
